/**
* 
* ====================================================================
*
* @author apov <apov@ymail.com>
*/ 
// StaticProcessInfo.h
//
#pragma once

#include "BaseDefine.h"

#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#include <excpt.h>
#include <dbgHelp.h>
#include <tchar.h>
#endif

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <string.h>
#include <iostream>
#include "ShareMemory.h"

static const std::string DEF_SHARED_NAME = "poplar_shared_names";

class StaticProcessInfo{
	typedef std::vector< std::string > StrContainer;	

public:
	enum{
		DEF_STR_TMP=					1024,

		DEF_SHARED_MEMORY_NAME_LEN=		128,
		DEF_SAHRED_MEMORY_NAME_COUNT=	100,

		DEF_SHARED_MEMORY_TYPE_DB=			1,
		DEF_SHARED_MEMORY_TYPE_NETWORK=		2,
	};

	struct SharedNames{
		int reg_time;
		int type;
		char names[ DEF_SHARED_MEMORY_NAME_LEN ];

		SharedNames(){				
			reg_time = 0;
			type = 0;
			memset( names, 0, sizeof( char ) * DEF_SHARED_MEMORY_NAME_LEN );
		}
	};

	void start();
	void register_msg( char* msg );
	int runtime_sec();
	void setExceptionHandler( int (*func)( void* ), char* name );
	void callExceptionHandler( void* data );

	void register_shared_name( char* name, int type );

	char* getName();

	static StaticProcessInfo* Instance( char* name = 0 );
	static void Shutdown();

	StaticProcessInfo( char* name );
	virtual ~StaticProcessInfo();

protected:

private:
	ShareMemory< SharedNames >* data_;
	StrContainer notice_;
	char uniq_name_[ DEF_STR_TMP ];
	int start_sec_;

	int (*func_)( void* );
};

//#pragma data_seg(".Share_base_define")
static StaticProcessInfo* StaticProcessInfo_ = 0;
//#pragma data_seg()
//#pragma comment(linker, "/SECTION:.Share_base_define,RWS")
